package tech.dx.springdb.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.dx.springdb.entity.Parents;
import tech.dx.springdb.service.ParentsService;

/**
 * @ClassName ParentsController
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/3 15:08
 * @Version 1.0
 */
@RestController
@RequestMapping("parents")
@Api(tags = {"父母"})
public class ParentsController {
    @Autowired
    private ParentsService parentsService;

    @PostMapping
    public Parents add(@RequestBody Parents parents){
        return parentsService.add(parents);
    }

    @PutMapping
    public Parents update(@RequestBody Parents parents){
        return parents.getId()==0?null:parentsService.update(parents);
    }

    @GetMapping(path = {"/{id}"})
    public Parents get(@PathVariable long id){
        Parents parents = new Parents();
        return parentsService.getById(id).orElse(parents);
    }

}
